<?php

namespace app\controller\web;

use app\exception\ErrnoPlus;
use app\service\DeviceInfoTableService;
use app\validate\PageValidate;
use app\validate\DeviceInfoTableValidate;
use share\exception\ApiException;
use share\utils\Helper;

class DeviceInfoTableController extends WebBaseController{

    public function initValidate(){        
        $this->validate = new DeviceInfoTableValidate();
    }


    /**
     * 列表 搜索
     */
    public function list_action(){
        $page = $this->check('pageInfo',null,(new PageValidate()));
        $input = $this->check();  
       
        $data = DeviceInfoTableService::getListInfo($input,$page);
        $data = Helper::arrayListReplaceKey($data,[
            'device_name' => 'deviceName',
            'iot_id' => 'iotId',
            'ch_num' => 'chNum',
            'extend_num' => 'extendNum',
            'server_site' => 'serverSite',
        ]);
        $total = DeviceInfoTableService::getListCountInfo($input);
        return self::ok(self::formatPageData($page,$total,$data));
    }

    /**
     * 获取设备的分享和绑定信息
     */
    public function get_share_binding_action(){
        $iotId = $this->request->param('iotId');
        if(empty($iotId)){
            throw new ApiException("iotId info empty",ErrnoPlus::COMMON_ERROR);
        }
        $res = DeviceInfoTableService::getShareBindingInfoByIotId($iotId);
        return self::ok($res);
    }

}